package com.basic.business.mat.controller;


import java.util.List;
import java.io.IOException;
import java.util.Map;

import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import com.basic.common.annotation.FileExport;
import com.basic.common.utils.easyExcel.EasyExcelUtils;
import org.springframework.web.bind.annotation.*;
import com.basic.common.annotation.Log;
import com.basic.common.core.controller.BaseController;
import com.basic.common.core.domain.AjaxResult;
import com.basic.common.enums.BusinessType;
import com.basic.business.mat.domain.TMatMgmt;
import com.basic.business.mat.service.ITMatMgmtService;
import com.basic.common.core.page.TableDataInfo;

/**
 * 材质管理Controller
 *
 * @author zhaoxy_jn@163.com
 */
@RestController
@RequestMapping("/business/matMgmt")
public class TMatMgmtController extends BaseController
{
    @Resource
    private ITMatMgmtService tMatMgmtService;

    /**
     * 查询材质管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:matMgmt:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMatMgmt tMatMgmt)
    {
        startPage();
        List<TMatMgmt> list = tMatMgmtService.getList(tMatMgmt);
        return getDataTable(list);
    }

    /**
     * 导出材质管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:matMgmt:export')")
    @Log(title = "材质管理", businessType = BusinessType.EXPORT)
    @FileExport(fileName = "材质管理.xlsx")
    @PostMapping("/export")
    public String export(TMatMgmt tMatMgmt) throws IOException
    {
        List<TMatMgmt> list = tMatMgmtService.getList(tMatMgmt);
        return EasyExcelUtils.excelExport(TMatMgmt.class,"材质管理数据", list);
    }

    /**
     * 获取材质管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:matMgmt:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tMatMgmtService.get(id));
    }

    /**
     * 新增材质管理
     */
    @PreAuthorize("@ss.hasPermi('business:matMgmt:add')")
    @Log(title = "材质管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMatMgmt tMatMgmt)
    {
        return toAjax(tMatMgmtService.insert(tMatMgmt));
    }


    /**
     * 状态变更
     */
    @PreAuthorize("@ss.hasPermi('business:matMgmt:changeStatus')")
    @Log(title = "材质管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestParam("ids") String[] ids, @RequestParam("status") String status)
    {
        return toAjax(tMatMgmtService.updateStatusByIds(ids, status));
    }

    /**
     * 修改材质管理
     */
    @PreAuthorize("@ss.hasPermi('business:matMgmt:edit')")
    @Log(title = "材质管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMatMgmt tMatMgmt)
    {
        return toAjax(tMatMgmtService.update(tMatMgmt));
    }

    /**
     * 删除材质管理
     */
    @PreAuthorize("@ss.hasPermi('business:matMgmt:remove')")
    @Log(title = "材质管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tMatMgmtService.deleteByIds(ids));
    }


    /**
     * 获得材质状态正常的列表
     */
    @GetMapping("/getNormalMatMgmtList")
    public AjaxResult getNormalMatMgmtList()
    {
        List<TMatMgmt> list = tMatMgmtService.getNormalMatMgmtList();
        return success(list);
    }

    /**
     * 字段重复判断
     */
    @GetMapping("/getDoesItExist")
    public AjaxResult getDoesItExist(TMatMgmt tMatMgmt)
    {
        List<TMatMgmt> list = tMatMgmtService.getDoesItExist(tMatMgmt);
        return success(list);
    }

}
